package com.postracker.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.postracker.dao.UserDao;
import com.postracker.model.User;
import com.postracker.service.UserManagementService;
import com.postracker.web.bean.UserBean;

@Service
@Transactional(readOnly = true)
public class UserManagementServiceImpl implements UserManagementService {

	@Autowired
	private UserDao userDao;

	@Override
	public List<UserBean> getAllUsers() {
		List<User> allUsers = userDao.findAll();
		return createUserBeanFromUsers(allUsers);
	}

	private List<UserBean> createUserBeanFromUsers(List<User> userList) {
		List<UserBean> userBeanList = new ArrayList<UserBean>();
		for (User user : userList) {
			userBeanList.add(new UserBean(user.getName()));
		}
		return userBeanList;
	}

}
